#!/usr/bin/env python3

import re
from email.utils import parseaddr
from urllib.parse import quote
import common

args, ignored = common.parse_args()
email_address, name = parseaddr(args.reviewer)
auth_token, section_config = common.parse_config(__file__)

if re.match(section_config.get('ignored_emails', '(?!)'), email_address) is not None:
    exit()


url = 'https://api.hipchat.com/v2/user/%s/message?auth_token=%s' % (quote(email_address), quote(auth_token))
message = 'Visit %s to review change in %s' % (args.changeUrl, args.project)
success_log_message = 'Reviewer %s added to %s' % (email_address, args.changeUrl)

common.perform_request(url, message, success_log_message)
